<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商户凭证列表</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="__PUBLIC__/admin/favicon.ico">
    <link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/animate.css" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet">
    <link href="__PUBLIC__/admin/js/plugins/iCheck/custom.css" rel="stylesheet">
    <!--<link href="__PUBLIC__/admin/js/layui/css/layui.css" rel="stylesheet">-->

</head>
<include file="Admin@Index:cache"/>
<body class="gray-bg contacts">
<style>
    .table-hover > tbody > tr > td {
        height: 4rem;
    }
</style>
<div class="wrapper wrapper-content animated fadeInRight" oncopy="copyval()">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-content">
                    <h2>商户凭证列表</h2>

                    <div class="col-sm-12" style="margin-bottom: 1rem">
                        <form role="form" action="__SELF__" method="get">
                            <div class="form-group">
                                <!--<label>商品code</label>-->
                                <input type="text" id="content" placeholder="" name="content" class="form-control">
                            </div>
                            <div>
                                <input  style="padding-bottom: 2px;width: 15%;height: 2.5rem;" autocomplete="off" class="laydate-icon" placeholder="选择时间" id="time" >

                                <input style="display: none" autocomplete="off" class="laydate-icon" placeholder="起始时间" id="start" name="start" > <input style="display: none;"class="laydate-icon"autocomplete="off"placeholder="截止时间" id="end" name="end">
                                <select id="time_type" name='time_type' class="form-control m-b"
                                        style="margin-bottom: 0;padding-top: 3px;display: inline;width: 10%;">
                                    <option value="should_time">时间类型</option>
                                    <option value="ctime">借款时间</option>
                                    <option value="repayment_time">还款时间</option>
                                </select>

                                <select name="status" id="status" class="form-control m-b"
                                        style="margin-bottom: 0;padding-top: 3px;display: inline;width: 10%;">
                                    <!--订单状态1未确认,2已确认,3已逾期,4续期,5已坏账,6已撕毁,7被拒绝9已打款-->
                                    <option value="">状态</option>
                                    <option value="0" <if condition="$_GET['status'] eq 0">selected</if> >待支付</option>
                                    <!--<option value="1" <if condition="$_GET['status'] eq 1">selected</if> >未确认</option>-->
                                    <option value="2" <if condition="$_GET['status'] eq 2">selected</if> >已确认</option>
                                    <option value="3" <if condition="$_GET['status'] eq 3">selected</if> >已逾期</option>
                                    <option value="4" <if condition="$_GET['status'] eq 4">selected</if> >已续借</option>
                                    <option value="5" <if condition="$_GET['status'] eq 5">selected</if> >已坏账</option>
                                    <option value="6" <if condition="$_GET['status'] eq 6">selected</if> >已撕毁</option>
                                    <option value="7" <if condition="$_GET['status'] eq 7">selected</if> >已拒绝</option>
                                    <option value="8" <if condition="$_GET['status'] eq 8">selected</if> >已作废</option>
                                    <option value="9" <if condition="$_GET['status'] eq 9">selected</if> >已打款</option>
                                </select>
                                <!--</div>-->
                                <a class="btn btn-success" style="margin-bottom: 3px" onclick="add_voucher()">+发起凭证</a>
                                <button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit" id="search">
                                    <strong>搜索</strong>
                                </button>

                            </div>
                        </form>
                    </div>
                    <br>
                    <table class="table table-striped table-hover">
                        <tbody>
                        <tr>
                            <!--<th class="">选择</th>-->
                            <th>编号</th>
                            <th>借款人姓名</th>
                            <th>借款人手机号</th>
                            <th>出借人姓名</th>
                            <th>借款金额</th>
                            <th>借款时间</th>
                            <th>应还款时间</th>
                            <th>撕毁时间</th>
                            <th>展期详情</th>
                            <th>
                                状态
                            </th>

                            <th>备注</th>
                            <th class="client-status">操作</th>

                        </tr>
                        <foreach name="list" item="list">
                            <tr>
                                <td><{$list.numbering}></td>
                                <td><{$list.borrower}></td>
                                <td>
                                    <{$list.mobile}>
                                </td>
                                <td><{$list.lender}></td>
                                <td><{$list.money}></td>
                                <td><{$list.loan_time}></td>
                                <td><{$list.repayment_time}></td>
                                <td><{$list.tear_time}></td>
                                <td><a class="btn btn-info btn-rounded " href="javascript:void(0);"
                                       onclick="get_period('<{$list.numbering}>','<{$list.repayment_time}>','<{$list.money}>')">展期详情</a>
                                </td>
                                <!--订单状态1未确认,2已确认,3已逾期,4续期,5已坏账,6已撕毁,7被拒绝9已打款-->
                                <td>
                                    <switch name="list.status">
                                        <case value="0">待支付</case>
                                        <case value="1">未确认</case>
                                        <case value="2">已确认</case>
                                        <case value="3">已逾期</case>
                                        <case value="4">已续期</case>
                                        <case value="5">已坏账</case>
                                        <case value="6">已撕毁</case>
                                        <case value="7">已被拒</case>
                                        <case value="8">已作废</case>
                                        <case value="9">已打款</case>
                                    </switch>
                                </td>

                                <td>
                                    <{$list.note}>
                                </td>
                                <td class="client-status">
                                    <a class="btn btn-info btn-rounded " href="javascript:void(0);"
                                       onclick="get_certificate_msg('<{$list.numbering}>','<{$list.status}>')">凭证详情</a>
                                    <?php if($list['status']!='5'){ ?>
                                    <a class="btn btn-danger btn-rounded" rid="<{$list.id}>" href="javascript:void(0);"
                                       onclick="set_voucher_bad_debt('<{$list.numbering}>');">坏账</a>
                                    <?php } ?>
                                    <?php if($list['status']!='6'){ ?>
                                    <a class="btn btn-primary btn-rounded" rid="<{$list.id}>" href="javascript:void(0);"
                                       onclick="set_voucher_status('<{$list.numbering}>','<{$list.loan_time}>');">撕毁</a>
                                    <?php } ?>
                                    <a class="btn btn-danger btn-rounded" rid="<{$list.id}>" href="javascript:void(0);"
                                       onclick="del_voucher('<{$list.numbering}>');">删除</a>
                                    <?php if($list['check_pay']=='1'){ ?>
                                    <a class="btn btn-warning btn-rounded" rid="<{$list.id}>" href="javascript:void(0);"
                                       onclick="pay_certificate('<{$list.numbering}>');">支付</a>
                                    <?php } ?>


                                    <!--<a class="btn btn-danger btn-rounded " href="javascript:void(0);" onclick="mark_reason('<{$list.repayment_no}>')" >备注</a>-->
                                </td>
                            </tr>
                        </foreach>
                        </tbody>
                    </table>
                    <input value="" id='ttt' style="display: none">
                    <ul class="pagination">

                        <{$fpage}>

                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
<script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>
<script src="__PUBLIC__/admin/js/layer/layer.js"></script>
<script src="__PUBLIC__/admin/js/laydate/laydate.js"></script>

<!-- 自定义js -->
<script src="__PUBLIC__/admin/js/content.js?v=1.0.0"></script>
<script src="__PUBLIC__/admin/js/plugins/fancybox/jquery.fancybox.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/ajaxfileupload.js"></script>

<script>
    $(document).ready(function () {
        $('.contact-box').each(function () {
            animationHover(this, 'pulse');
        });
    });


    $(document).ready(function () {
        $('.fancybox').fancybox({
            openEffect: 'none',
            closeEffect: 'none'
        });
    });

    laydate.render({
        elem:'#time',
        range:true,
        done: function(value, date, endDate){
            $('#time').val(value);
            var time=value.split(' - ');
            $('#start').val(time[0]);
            $('#end').val(time[1]);
        }
    });

    //添加凭证
    function add_voucher() {
        get_lender();
        var rate = '<{$rate}>';
        console.log(rate);
        var html = '';
        html += '<div class="modal-body" id="lists" style="height:100%">';
        html += '<form class="form-horizontal">';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >借款时间：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="borrow_time" autocomplete="off" placeholder="借款时间" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >还款时间：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="repayment_time" autocomplete="off" placeholder="还款时间" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >借款金额：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="number" id="borrow_money" placeholder="借款金额" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >实际到账：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="number" id="actual_money" placeholder="实际到账金额" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >年化利率：</label>';
        html += '<div class="col-sm-8">';
        html += '<select class="form-control m-b" name="rate" id="rate" style="height:3rem">';
        $(eval('(' + rate + ')')).each(function (k, v) {
            html += '<option value="' + v + '">' + v + '%</option>';
        });
        html += '</select>';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >出借人：</label>';
        html += '<div class="col-sm-8">';
        html += '<select class="form-control m-b" name="User" id="lender" style="height:3rem">';

        html += '</select>';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >借款人账号：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="borrow_mobile" placeholder="手机号" onchange="get_msg(this.value)" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >借款人姓名：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="borrow_user_name" disabled placeholder="借款人姓名" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >借款人身份证号：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="borrow_user_idcard" disabled placeholder="出借人" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >备注：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="mark" placeholder="备注" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '</form>';
        html += '<div class="modal-footer" style="border:0">';
        html += '<a href="javascript:void(0);" onclick="layer.closeAll()" type="button" class="btn btn-default" >关闭</a>';
        html += '<a href="javascript:void(0);" onclick="add_vouchers();" type="button" class="btn btn-primary" >发起</a>';
        html += '</div>';
        html += '</div>';

        layer.open({
            type: 1, //Page层类型
            area: ['500px', '680px'],
            title: '发起凭证',
            shade: 0.6, //遮罩透明度
            maxmin: true, //允许全屏最小化
            anim: 1, //0-6的动画形式，-1不开启
            content: html
        });
        var now_time="<?= date('Y-m-d')?>";
        var next_time="<?= date('Y-m-d',strtotime('+1 day'))?>";
        var option=new Object();

        var repayment=laydate.render({
            elem:'#repayment_time',
            min:next_time,
            btns:['confirm'],
            istoday:false,
            done:function(value, date, endDate){
                if($('#borrow_time').val()==''){
                    layer.msg('请先选择借款时间', {time: 1000, icon: 5});
                    $('#repayment_time').val('');
                }
            }
        });

        var borrow=laydate.render({
            elem:'#borrow_time',
            istoday: false, //是否显示今天
            min: now_time,
            ready:function(date){
                $('#borrow_time').val(now_time);
            },
            done: function(value, dates){

                $('#repayment_time').val('');
//                var new_time =value.split('-');
//                var min_time = timetrans(new Date(new_time[0], new_time[1], new_time[2]).getTime() + 24 * 3600000);
//                var min_time=min_time.split('-');
                //以下参数必须为数字
                repayment.config.min={
                    year:dates.year,
                    month:dates.month-1,//关键
                    date: dates.date+1
                };
            }
        });


    }
    //获取出借人
    function get_lender() {
        $.post('__MODULE__/Mypublic/get_lender', {post: 'ffsdnfweofhfa'}, function (data) {
            console.log(data);
            if (data.code == '1001') {
                var html = '';
                $(data.result).each(function (k, v) {
                    html += '<option value="' + v.id + '">' + v.name + '</option>';
                });
                $('#lender').html(html);
            } else {
                if (data.status == '0') {
                    layer.msg(data.info, {time: 2000, icon: 5});
                } else {
                    $('#lender').append(data.result);
                }
            }
        });
    }

    //获取借款人信息
    function get_msg(param) {
        $.post('__MODULE__/Mypublic/get_borrow_user_msg', {param: param}, function (data) {
            if (data.code == '1001') {
                $('#borrow_user_name').val(data.result.username);
                $('#borrow_user_idcard').val(data.result.identity_num);
            } else {
                if (data.status == '0') {
                    layer.msg(data.info, {time: 1000, icon: 5});
                } else {
                    layer.msg(data.result, {time: 1000, icon: 5});
                }
            }
        });
    }
    //添加凭证
    function add_vouchers() {
        layer.confirm('是否确定发起凭证？', function () {
            layer.load(2);
            $.post('__MODULE__/Voucher/add_voucher', {
                borrow_time: $('#borrow_time').val(),
                repayment_time: $('#repayment_time').val(),
                borrow_money: $('#borrow_money').val(),
                actual_money: $('#actual_money').val(),
                rate: $('#rate').val(),
                lender: $('#lender').val(),
                borrow_mobile: $('#borrow_mobile').val(),
                mark: $('#mark').val()
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == '1001') {
                    layer.closeAll();
                    layer.msg(data.result,{icon: 1,time:1000}, function(){
                        window.location.reload();
//                        window.location.href='__CONTROLLER__/merchant_debit_no_confirm_list';
                    });
                } else {
                    if (data.status == '0') {
                        layer.msg(data.info, {time: 2000, icon: 5});
                    } else {
                        layer.msg(data.result, {time: 2000, icon: 5});
                    }
                }
            })
        });
    }

    //获取续期信息
    function get_period(numbering, repayment_times, money) {
        $.post('__MODULE__/Mypublic/get_certificate_period', {numbering: numbering}, function (data) {
            console.log(data);
            if (data.code == '1001') {
                var html = '';
                html += '<div class="modal-body" id="lists" style="height:100%">';
                html += '<form class="form-horizontal">';
                html += '<div class="form-group">';
                html += '<div class="col-sm-12">';
                html += '<div style="padding: 10px 0;display:flex" id="period"><span style="width: 15%">展期本金</span><span style="width: 20%">原还款日</span><span style="width: 20%">现还款日</span><span style="width: 10%">利息</span><span style="width: 10%">年利率</span><span style="width: 15%">展期天数</span><span style="width: 10%">状态</span></div>';
                if (data.result != '') {
//                    var reason=eval('('+data.result+')');
                    $(data.result).each(function (k, v) {
                        html += '<div style="padding: 10px 0;display:flex"><span style="width: 15%">' + v.money + '</span><span style="width: 20%">' + v.repayment_time + '</span><span style="width: 20%">' + v.period_time + '</span><span style="width: 10%">' + v.interest + '</span><span style="width: 10%">' + v.interest_rate + '%</span><span style="width: 15%">' + v.period_days + '</span><span style="width: 10%">' + v.status + '</span></div>';
                    });
                } else {
                    html += '<div style="padding: 10px 0;font-size:2rem">暂无记录</div>';
                }
                html += '</div>';
                html += '</div>';
                html += '<p id="pp"></p>';
                html += '</form>';
                html += '<div class="modal-footer" style="padding-top:1rem;position:relative;border:none">';
                html += '<a href="javascript:void(0);" onclick="layer.closeAll()" type="button" class="btn btn-default" >关闭</a>';
                if (data.check == '1') {
                    html += '<a href="javascript:void(0);" onclick="add_period(\'' + numbering + '\',\'' + data.repayment_time + '\',\'' + money + '\');" type="button" class="btn btn-primary" >添加展期</a>';
                }
                html += '</div>';
                html += '</div>';
                layer.open({
                    type: 1, //Page层类型
                    area: ['600px', '400px'],
                    title: '续期信息',
                    shade: 0.6, //遮罩透明度
                    maxmin: true, //允许全屏最小化
                    anim: 1, //0-6的动画形式，-1不开启
                    content: html
                });
            } else {
                if (data.status == '0') {
                    layer.msg(data.info, {time: 2000, icon: 5});
                } else {
                    layer.msg(data.result, {time: 2000, icon: 5});
                }
            }
        });
    }

    function add_period(numbering, repayment_time, money) {
        var rate = '<{$rate}>';
        var html = '';
        html += '<div class="modal-body" id="lists" style="height:100%">';
        html += '<form class="form-horizontal">';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >续借本金：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="benjin" disabled value="' + money + '" autocomplete="off" placeholder="" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >原还款日：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="repayment_time" disabled value="' + repayment_time + '" autocomplete="off" placeholder="还款时间" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >续期至：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="period_time" placeholder="" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >续期天数：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="number" id="period_day" disabled placeholder="续期天数" class="form-control">';
        html += '</select>';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >年化利率：</label>';
        html += '<div class="col-sm-8">';
        html += '<select class="form-control m-b" onchange="get_rate(\'' + money + '\',this.value)" name="rate" id="rate" style="height:3rem">';
        html += '<option value="0">0</option>';
        $(eval('(' + rate + ')')).each(function (k, v) {
            html += '<option value="' + v + '">' + v + '%</option>';
        });
        html += '</select>';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >利息：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="fee" value="0" disabled placeholder="利息" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '</form>';
        html += '<div class="modal-footer" style="border:0">';
        html += '<a href="javascript:void(0);" onclick="layer.closeAll()" type="button" class="btn btn-default" >关闭</a>';
        html += '<a href="javascript:void(0);" onclick="add_periods(\'' + numbering + '\');" type="button" class="btn btn-primary" >提交</a>';
        html += '</div>';
        html += '</div>';
        layer.open({
            type: 1, //Page层类型
            area: ['500px', '500px'],
            title: '续期',
            shade: 0.6, //遮罩透明度
            maxmin: true, //允许全屏最小化
            anim: 1, //0-6的动画形式，-1不开启
            content: html
        });
        var new_time = repayment_time.split('-');
        var min_time = timetrans(new Date(new_time[0], new_time[1], new_time[2]).getTime() + 24 * 3600000);
        laydate.render({
            elem:'#period_time',
            min: min_time,
            istoday:false,
            btns:['confirm'],
            done: function(value, date, endDate){
                console.log(value); //得到日期生成的值，如：2017-08-18
                console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
//                start.max = value; //结束日选好后，重置开始日的最大日期
                $('#rate').val('0');
                $('#fee').val('0');
                get_period_day(value, repayment_time);
            }
        });

    }
    //获取续期天数
    function get_period_day(time, repayment_time) {
        var new_time = time.split('-');
        var new_time = new Date(new_time[0], new_time[1], new_time[2]).getTime();
        var old_time = repayment_time.split('-');
        var old_time = new Date(old_time[0], old_time[1], old_time[2]).getTime();
        var day = (new_time - old_time) / (24 * 3600000);
        $('#period_day').val(day);
    }
    //获取利息
    function get_rate(money, rate) {
        var day = $('#period_day').val();
        if (day == '') {
            layer.msg('请先选择续借日期', {time: 1000, icon: 5});
            $('#rate').val('0');
            return false;
        }
        var fee = money * (rate / 100) * day / 365;
        $('#fee').val(fee.toFixed(2));
    }
    //添加展期
    function add_periods(numbering) {
        layer.confirm('是否确定进行续期？', function () {
            layer.load(2);
            $.post('__MODULE__/Voucher/add_certificate_period', {
                numbering: numbering,
                repayment_time: $('#repayment_time').val(),
                period_time: $('#period_time').val(),
                rate: $('#rate').val(),
                fee: $('#fee').val()
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == '1001') {
                    layer.closeAll();
                    layer.msg(data.result,{icon: 1,time:1000}, function(){
                        window.location.reload();
                    });
                } else {
                    if (data.status == '0') {
                        layer.msg(data.info, {time: 2000, icon: 5});
                    } else {
                        layer.msg(data.result, {time: 2000, icon: 5});
                    }
                }
            })
        });
    }

    function timetrans(date) {
        var date = new Date(date);//如果date为10位不需要乘1000
        var Y = date.getFullYear() + '-';
        var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth()) : date.getMonth()) + '-';
        var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
        return Y + M + D;
    }

    //获取凭证信息
    function get_certificate_msg(orderno, status) {
        $.post('__MODULE__/Mypublic/get_certificate_msg', {orderno: orderno}, function (data) {
            if (data.code == '1001') {
                console.log(data);
                var html = '';
                html += '<div class="modal-body" id="lists" style="height:100%">';
                html += '<form class="form-horizontal">';
                html += '<div class="form-group">';
                html += '<label class="col-sm-3 control-label" >借款时间：</label>';
                html += '<div class="col-sm-8">';
                html += '<input type="text" id="borrow_time"  disabled value="' + data.result.loan_time + '" placeholder="借款时间" class="form-control">';
                html += '</div>';
                html += '</div>';
                html += '<div class="form-group">';
                html += '<label class="col-sm-3 control-label" >还款时间：</label>';
                html += '<div class="col-sm-8">';
                html += '<input type="text" id="repayment_time" disabled value="' + data.result.repayment_time + '" placeholder="还款时间" class="form-control">';
                html += '</div>';
                html += '</div>';
                html += '<div class="form-group">';
                html += '<label class="col-sm-3 control-label" >借款金额：</label>';
                html += '<div class="col-sm-8">';
                html += '<input type="number" id="borrow_money" disabled value="' + data.result.money + '"  placeholder="借款金额" class="form-control">';
                html += '</div>';
                html += '</div>';
                html += '<div class="form-group">';
                html += '<label class="col-sm-3 control-label" >实际到账：</label>';
                html += '<div class="col-sm-8">';
                html += '<input type="number" id="borrow_money" disabled value="' + data.result.actual_money + '"  placeholder="实际到账金额" class="form-control">';
                html += '</div>';
                html += '</div>';
                html += '<div class="form-group">';
                html += '<label class="col-sm-3 control-label" >年化利率：</label>';
                html += '<div class="col-sm-8">';
                html += '<input type="text" disabled value="' + data.result.interest_rate + '%" placeholder="年化率" class="form-control">';
                html += '</div>';
                html += '</div>';
                html += '<div class="form-group">';
                html += '<label class="col-sm-3 control-label" >备注：</label>';
                html += '<div class="col-sm-8">';
                html += '<input type="text" disabled value="' + data.result.note + '" placeholder="备注" class="form-control">';
                html += '</div>';
                html += '</div>';
                html += '</form>';
                html += '<div class="modal-footer" style="border:0">';
                html += '<a href="javascript:void(0);" onclick="layer.closeAll()" type="button" class="btn btn-default" >关闭</a>';
                if (status == '2') {
                    html += '<a href="javascript:void(0);" onclick="play_money(\'' + data.result.numbering + '\');" type="button" class="btn btn-primary" >确定打款</a>';
                }
                if(status!='1' && status!='7'){
                    html += '<a href="javascript:void(0);" onclick="add_play_money_record(\'' + data.result.money + '\',\'' + data.result.numbering + '\');" type="button" class="btn btn-success" >添加打款记录</a>';
                }
                html += '</div>';
                html += '</div>';

                layer.open({
                    type: 1, //Page层类型
                    area: ['500px', '430px'],
                    title: '凭证详情',
                    shade: 0.6, //遮罩透明度
                    maxmin: true, //允许全屏最小化
                    anim: 1, //0-6的动画形式，-1不开启
                    content: html
                });
            } else {
                if (data.status == '0') {
                    layer.msg(data.info, {time: 1000, icon: 5});
                } else {
                    layer.msg(data.result, {time: 1000, icon: 5});
                }
            }
        });
    }

    function play_money(orderno) {
        layer.confirm('是否确定已打款？', function () {
            layer.load(2);
            $.post('__MODULE__/Voucher/play_money', {
                orderno: orderno
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == '1001') {
                    window.location.reload();
                } else {
                    if (data.status == '0') {
                        layer.msg(data.info, {time: 2000, icon: 5});
                    } else {
                        layer.msg(data.result, {time: 2000, icon: 5});
                    }
                }
            });
        });
    }

    function add_play_money_record(money, orderno) {
        var html = '';
        html += '<div class="modal-body" id="lists" style="height:100%">';
        html += '<form class="form-horizontal">';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >打款金额：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="actual_money" value="' + money + '" placeholder="打款金额" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-3 control-label" >支付方式：</label>';
        html += '<div class="col-sm-8">';
        html += '<select class="form-control m-b" name="rate" id="pay_type" style="height:3rem">';
        html += '<option value="1">银行卡</option>';
        html += '<option value="2">支付宝</option>';
        html += '<option value="3">微信</option>';
        html += '<option value="4">其他</option>';
        html += '</select>';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<input type="file" onchange="uploadimgs()" id="uploadimg" name="uploadimg" style="display:none" accept="image/jpeg,image/jpg,image/png" value="">';
        html += '<label class="col-sm-3 control-label" for="uploadimg"><a class="btn btn-success">上传凭证</a></label>';
        html += '<div class="col-sm-8" id="newimg">';
        html += '<img style="width:10rem" src="__PUBLIC__/admin/img/webuploader.png">';
        html += '</div>';
        html += '<input type="text" id="img_url"  style="display: none"  placeholder="" class="form-control">';
        html += '</div>';
        html += '</form>';
        html += '<div class="modal-footer" style="border:0">';
        html += '<a href="javascript:void(0);" onclick="layer.closeAll()" type="button" class="btn btn-default" >关闭</a>';
        html += '<a href="javascript:void(0);" onclick="add_play_money_records(\'' + orderno + '\');" type="button" class="btn btn-primary" >打款</a>';
        html += '</div>';
        html += '</div>';

        layer.open({
            type: 1, //Page层类型
            area: ['500px', '500px'],
            title: '添加打款记录',
            shade: 0.6, //遮罩透明度
            maxmin: true, //允许全屏最小化
            anim: 1, //0-6的动画形式，-1不开启
            content: html
        });
    }

    function add_play_money_records(orderno) {
        layer.confirm('是否确定添加？', function () {
            layer.load(2);
            var pay_type = $("#pay_type").val();
            var img_url = $("#img_url").val();
            $.post('__MODULE__/Voucher/add_play_money_record', {
                actual_money: $("#actual_money").val(),
                pay_type: pay_type,
                img_url: img_url,
                orderno: orderno
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == '1001') {
                    layer.closeAll();
                    layer.msg(data.result,{icon: 1,time:1000}, function(){
                        window.location.reload();
                    });
                } else {
                    if (data.status == '0') {
                        layer.msg(data.info, {time: 2000, icon: 5});
                    } else {
                        layer.msg(data.result, {time: 2000, icon: 5});
                    }
                }
            });
        });
    }

    function uploadimgs() {
        var url = '__MODULE__/Mypublic/uploadimg';
        layer.load(2);
        $.ajaxFileUpload({
            url: url,//需要链接到服务器地址
            secureuri: false,
            fileElementId: 'uploadimg',//文件选择框的id属性file的id
            dataType: 'json',
            success: function (data) {
                layer.closeAll('loading');
                console.log(data);
                if (data.code == '1001') {
                    var html = '<img  style="width:15rem" src="' + data.result + '" >';
                    $('#newimg').html(html);
                    $('#img_url').val(data.result);
                } else {
                    if (data.status == '0') {
                        layer.msg(data.info, {icon: 5, time: 2000});
                    } else {
                        layer.msg(data.result, {icon: 5, time: 2000});
                    }
                }
            }
        });
    }

    //设置坏账
    function set_voucher_bad_debt(orderno) {
        layer.confirm('是否确定设置为坏账', function () {
            layer.load(2);
            $.post('__MODULE__/Voucher/set_voucher_bad_debt', {orderno: orderno}, function (data) {
                layer.closeAll();
                if (data.code == '1001') {
                    layer.closeAll();
                    layer.msg(data.result,{icon: 1,time:1000}, function(){
                        window.location.reload();
                    });
                } else {
                    if (data.status == '0') {
                        layer.msg(data.info, {time: 2000, icon: 5});
                    } else {
                        layer.msg(data.result, {time: 2000, icon: 5});
                    }
                }
            });
        });
    }

    //撕毁
    function set_voucher_status(orderno,loan_time) {
        var html = '';
        html += '<div class="modal-body" id="lists" style="height:100%">';
        html += '<form class="form-horizontal">';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >实际还款：</label>';
        html += '<div class="col-sm-7">';
        html += '<input type="number" id="real_repayment_money"  placeholder="实际到账（选填）" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >还款时间：</label>';
        html += '<div class="col-sm-7">';
        html += '<input type="text" id="real_repayment_time"  placeholder="实际还款时间" class="form-control">';
        html += '</div>';
        html += '</div>';

        html += '</form>';
        html += '<div class="modal-footer" style="border:0">';
        html += '<a href="javascript:void(0);" onclick="layer.closeAll()" type="button" class="btn btn-default" >关闭</a>';
        html += '<a href="javascript:void(0);" onclick="set_voucher_status_s(\'' + orderno + '\');" type="button" class="btn btn-primary" >撕毁</a>';
        html += '</div>';
        html += '</div>';
        layer.open({
            type: 1, //Page层类型
            area: ['400px', '250px'],
            title: '撕毁凭证',
            shade: 0.6, //遮罩透明度
            maxmin: true, //允许全屏最小化
            anim: 1, //0-6的动画形式，-1不开启
            content: html
        });

        laydate.render({
            elem:'#real_repayment_time',
            min: loan_time,
            istoday:false,
            btns:['confirm'],
            done: function(value, date, endDate){

            }
        });

    }

    function set_voucher_status_s(orderno) {
        layer.confirm('是否确定撕毁凭证', function () {
            layer.load(2);
            $.post('__MODULE__/Voucher/set_voucher_status',
                    {
                        orderno: orderno,
                        real_repayment_money:$('#real_repayment_money').val()
                    },
                    function (data) {
                        layer.closeAll();
                        if (data.code == '1001') {
                            layer.closeAll();
                            layer.msg(data.result,{icon: 1,time:1000}, function(){
                                window.location.reload();
                            });
                        } else {
                            if (data.status == '0') {
                                layer.msg(data.info, {time: 2000, icon: 5});
                            } else {
                                layer.msg(data.result, {time: 2000, icon: 5});
                            }
                        }
                    });
        });
    }

    //删除
    function del_voucher(orderno) {
        layer.confirm('是否确定删除凭证', function () {
            layer.load(2);
            $.post('__MODULE__/Voucher/del_voucher', {orderno: orderno}, function (data) {
                layer.closeAll();
                if (data.code == '1001') {
                    layer.closeAll();
                    layer.msg(data.result,{icon: 1,time:1000}, function(){
                        window.location.reload();
                    });
                } else {
                    if (data.status == '0') {
                        layer.msg(data.info, {time: 2000, icon: 5});
                    } else {
                        layer.msg(data.result, {time: 2000, icon: 5});
                    }
                }
            });
        });
    }

    //支付
    function pay_certificate(numbering) {
        layer.confirm('是否确定进行支付操作？', function () {
            layer.load(2);
            $.post('__MODULE__/Voucher/pay_certificate', {
                numbering: numbering,
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == '1001') {
                    document.write(data.result);
                } else {
                    if (data.status == '0') {
                        layer.msg(data.info, {time: 2000, icon: 5});
                    } else {
                        layer.msg(data.result, {time: 2000, icon: 5});
                    }
                }
            })
        });
    }


    function copyval() {
//        event.returnValue = false;
        var content = window.getSelection().toString();
        $.post('__MODULE__/Mypublic/copy_all', {content: '【商户凭证列表】复制：'+content}, function (data) {
            if (data.code == '1001') {
            } else {
                console.log(data);
            }
        });
//        console.log(content)
    }
</script>


</body>

</html>
